package com.example.music.Test;

import cn.hutool.http.HttpRequest;
import com.example.music.utility.MyUtil;
import org.springframework.util.DigestUtils;

import java.util.HashMap;

/**
 * 酷狗音乐
 *
 * @author yzh
 * @date 2023/04/12
 */
public class kugou {
    public static void main(String[] args) {
        /* f497233dd9135c631c7ff88c76a36ec6*/
        /* /v2/get_other_list_file?appid=1001&clientver=10137&plat=3&type=1&module=NONE&page=1&pagesize=100&global_collection_id=collection_3_1482394796_226_0&signature=f497233dd9135c631c7ff88c76a36ec6;*/

        String s = "NVPh5oo715z5DIWAeQlhMDsWXXQV4hwtappid=1001clientver=10137plat=3type=1module=NONEpage=1pagesize=100global_collection_id=collection_3_1482394796_226_0clienttime=1681357292863NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt";
        String s1 = DigestUtils.md5DigestAsHex(s.getBytes());
        System.out.println(s1);

    }

    /**
     * 获取音乐网址
     *
     * @param id id
     */
    public static void get_music_url(String id) {
        String url = "https://wwwapi.kugou.com/yy/index.php";
        HashMap<String, Object> map = new HashMap<>();
        map.put("r", "play/getdata");
        map.put("mid", "cb55d299c3f2144048653113dc1caafa");
        map.put("encode_album_audio_id", id);
        String s = HttpRequest.get(url)
                .timeout(20000)//超时，毫秒
                .form(map)
                .execute().body();
        System.out.println(s);
    }

    public static void search(String keyword) {
        //酷狗是获取的时间，每次不一样，这里可以写死,可以看作是盐，除了这个参数和搜索的关键词，其他参数都是一样的
        String clienttime = "1681282842933";
        //加密的字符串
        String base = "NVPh5oo715z5DIWAeQlhMDsWXXQV4hwtappid=1014bitrate=0callback=callback123clienttime=" + clienttime + "clientver=1000dfid=3exnMG1cUUsM38yA6h26SVo9filter=10inputtype=0iscorrection=1isfuzzy=0keyword=" + keyword + "mid=cb55d299c3f2144048653113dc1caafapage=1pagesize=30platform=WebFilterprivilege_filter=0srcappid=2919token=userid=0uuid=cb55d299c3f2144048653113dc1caafaNVPh5oo715z5DIWAeQlhMDsWXXQV4hwt";
        //md5加密获得signature
        String signature = DigestUtils.md5DigestAsHex(base.getBytes());
        //歌曲查询链接
        String url = "https://complexsearch.kugou.com/v2/search/song?callback=callback123&srcappid=2919&clientver=1000&clienttime=" + clienttime + "&mid=cb55d299c3f2144048653113dc1caafa&uuid=cb55d299c3f2144048653113dc1caafa&dfid=3exnMG1cUUsM38yA6h26SVo9&keyword=" + keyword + "&page=1&pagesize=30&bitrate=0&isfuzzy=0&inputtype=0&platform=WebFilter&userid=0&iscorrection=1&privilege_filter=0&filter=10&token=&appid=1014&signature=" + signature + "";
        //访问链接
        String s = HttpRequest.get(url)
                .timeout(20000)//超时，毫秒
                .execute().body();
        System.out.println(s);
    }

    public static void search_playList(String keyword) {
        //加密的字符串
        String base = "NVPh5oo715z5DIWAeQlhMDsWXXQV4hwtappid=1014callback=callback123clienttime=1681284717190clientver=20000dfid=-filter=10iscorrection=1keyword=" + keyword + "mid=1681284717190page=1pagesize=30platform=WebFilterprivilege_filter=0srcappid=2919userid=0uuid=1681284717190NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt";
        //md5加密获得signature
        String signature = DigestUtils.md5DigestAsHex(base.getBytes());
        //歌曲查询链接
        String url = "https://complexsearch.kugou.com/v1/search/special?callback=callback123&keyword=" + keyword + "&page=1&pagesize=30&userid=0&clientver=20000&platform=WebFilter&iscorrection=1&privilege_filter=0&filter=10&appid=1014&srcappid=2919&clienttime=1681284717190&mid=1681284717190&uuid=1681284717190&dfid=-&signature=" + signature + "";
        //访问链接
        String s = HttpRequest.get(url)
                .timeout(20000)//超时，毫秒
                .execute().body();
        System.out.println(s);
    }
}
